Learn R Programming

BigDataStatMeth (version 2.0.3)

[.HDF5Matrix: Subset an HDF5Matrix

Description

Subset an HDF5Matrix

Usage

# S3 method for HDF5Matrix
[(x, i, j, drop = TRUE, ...)

Value

Numeric matrix, or vector when drop = TRUE and one dimension has length 1

Arguments

x

An HDF5Matrix object

i

Row indices: numeric, integer, logical, or missing

j

Column indices: numeric, integer, logical, or missing

drop

Logical, whether to drop dimensions for single row/column results (default TRUE)

...

Ignored

Details

All standard R indexing modes are supported:

  • Contiguous ranges: X[1:100, 1:50]

  • Non-contiguous: X[c(1,3,5), c(2,4)]

  • Negative: X[-c(1,2), ] (all except rows 1 and 2)

  • Logical: X[row_mask, col_mask]

  • Missing: X[, ] (entire dataset)

Examples

Run this code
# \donttest{
tmp <- tempfile(fileext = ".h5")

X  <- hdf5_create_matrix(tmp, "data/matrix", data = matrix(rnorm(100), 10, 10))
X <- hdf5_matrix(tmp, "data/matrix")

X[1:5, 1:3]               # submatrix
X[1, ]                    # single row as vector
X[1, , drop = FALSE]      # single row as matrix
X[, 2]                    # single column as vector
X[-c(1, 10), ]            # all except first and last row
X[c(TRUE, FALSE), ]       # logical row index
X[, ]                     # entire dataset

X$close()
unlink(tmp)
# }

Run the code above in your browser using DataLab